﻿define(function (require) {
    var utility = require('ezdesk/utility/utility.js');

    return Backbone.View.extend({
        //... is a list tag.
        tagName: "li",
        template: _.template($("#li_notification").html()),
        events: {
            //'click . notification-link': 'clear'    
        },
        initialize: function () {
            var $self = this;
            $(this.el).attr('data-theme', 'd')
                      .addClass('ui-btn ui-btn-icon-right ui-li ui-btn-up-d  noti')

            _.bindAll(this, 'render');
            this.model.bind('change', this.render);
            this.model.view = this;
        },
        render: function () {
            var _model = this.model;
            $(this.el).html(this.template(this.model.toJSON()));

            var element = $(this.el)[0];
            var alink = $(element).find('.body').find('.ezlink');
            $(element).find('.feed-close').remove();

            alink.each(function () {
                //去掉连接中的回车 和 一些 带有空内容的连接
                if (this.firstChild.innerHTML == "<br>" || this.firstChild.innerHTML == "") return;
                $(this).addClass('notification-link');

                $(this).appendTo($(element).find(".action-r"));
            })

            $(this.el).find('a.ezlink').each(function (index, item) {
                var feedId = _model.get('FeedId');
                utility.HandleATag(item, function () {
                    _model.setIsRead(true);
                }, feedId);

            });
            
            return this;
        },
        remove: function () {
            $(this.el).remove();
        },

        // Remove the item, destroy the model.
        clear: function (e) {
            //edit feed status
            this.model.setIsAvailable();
        }
    });
});